data <- read.csv("apology_study2.csv")

#SDO
SDO.mat <- data[c(8:23)]
SDO.mat[c(9:16)] <- (8)- SDO.mat[c(9:16)]
SDO <- apply(SDO.mat[1:16], 1, mean)

#dependent variables
colonial.rule = scale(data$ap1)
confort.woman = scale(data$ap2)
massacre = scale(data$ap3)
war.apology = (colonial.rule + confort.woman + massacre) / 3

data <- cbind(data,  SDO, colonial.rule, confort.woman, massacre, war.apology)

colonial.apology = colonial.rule * -1
confort.woman.apology = confort.woman * -1
massacre.apology = massacre * -1
resistance.to.apologies = war.apology * -1

data <- cbind(data,  colonial.apology, confort.woman.apology, massacre.apology, resistance.to.apologies)

#centering independent variable and moderator
Ideology.centered <- data$Ideology - mean(data$Ideology, na.rm = TRUE)
Knowledge.centered <- data$Knowledge - mean(data$Knowledge, na.rm = TRUE)

data2 <- cbind(data, Ideology.centered, Knowledge.centered)

#Table6 Moderation Effect of Political Knowledge on the Association between Conservatism and Resistance to Group Apologies
library("pequod") 

Table6 <- lmres(resistance.to.apologies ~ Age + Gender.male + Education + SDO + Militaism + Ideology * Knowledge, centered = c("Ideology", "Knowledge"), data = data2)
summary(Table6)

#Table7 Moderation Effect of Political Knowledge on the Association between Attitude toward Interpersonal Apology and Resistance to Group Apologies
library("pequod") 

Table7 <- lmres(resistance.to.apologies ~ Age + Gender.male + Education + SDO + Militaism + Ideology + indap * Knowledge, centered = c("indap", "Knowledge"), data = data2)
summary(Table7)

#Table8 Moderation Effect of Political Knowledge on the Association between Attitude toward Neighboring Countries and Resistance to Group Apologies
library("pequod") 

Table8 <- lmres(resistance.to.apologies ~ Age + Gender.male + Education + SDO + Militaism + Ideology + Neighbor * Knowledge, centered = c("Neighbor", "Knowledge"), data = data2)
summary(Table8)

#Fig4 Interaction effect between conservative ideology and political knowledge.
library("ggplot2")
model <- lmres(resistance.to.apologies ~ Age + Gender.male + Education + SDO + Militaism + Ideology * Knowledge, centered = c("Ideology", "Knowledge"), data = data2)
model_ss <- simpleSlope(model, pred = "Ideology", mod1 = "Knowledge")
summary(model_ss)
PlotSlope(model_ss, namex = "Conservatism", namey = "Resistance to apologies", limitx=c(-2,2), limity=c(-1.7,-1.1))


#Fig2 Interaction effect between conservative ideology and political sophistication.
library("interplot")

reg.center <- lm(resistance.to.apologies ~ data2$Age + data2$Gender.male + data2$Education + data2$SDO + data2$Militaism  + Ideology.centered*Knowledge.centered)

int1 <- interplot(m = reg.center, var1 = "Ideology.centered", var2 = "Knowledge.centered") +
  labs(x = "Political knowledge", y = "Effects of conservatism")
print(int1)

